package com.crealth.memcached;

import java.util.List;
import com.crealth.db.ConsumerDb;
import com.crealth.model.ConsumerCreditCardModel;

public class ConsumerCreditCardCached {
	private static final String creditCardKeyPrefix = "creditCard_csmid_";
	
	@SuppressWarnings("unchecked")
	public static List<ConsumerCreditCardModel> selectConsumerCreditCard(int consumerID) {
		String key = creditCardKeyPrefix + consumerID;
		Object obj = MemcachedMgr.cachedClient.get(key);
		List<ConsumerCreditCardModel> cardls = null;
		if (obj != null) {
			cardls = (List<ConsumerCreditCardModel>)obj;
		}
		else {
			cardls = ConsumerDb.selectConsumerCreditCard(consumerID);
			if (cardls != null) {
				MemcachedMgr.cachedClient.set(key, cardls);
			}
		}
		
		return cardls;
	}
	
	public static void deleteCached(int consumerID) {
		String key = creditCardKeyPrefix + consumerID;
		MemcachedMgr.cachedClient.delete(key);
	}
	
}
